
PK2CMD = pk2cmd -PPIC18F2550
PROCESSOR = 18f2550
#PROCESSOR = 18f2455

#GPLINK_INCLUDE_DIR = -I"/usr/bin/../share/sdcc/lib/pic16" -I"/usr/share/sdcc/lib/pic16" -I"/usr/bin/../share/sdcc/lib" -I"/usr/share/sdcc/lib"
#SDCC_INCLUDE_DIR = "-I/usr/share/sdcc/include"
#SDCC_LIB_DIR = "-L/usr/share/sdcc/lib/pic16"

# on imac...
GPLINK_INCLUDE_DIR = 	-I"/opt/local/bin/../share/sdcc/lib/pic16" -I"/opt/local/share/sdcc/lib/pic16" -I"/opt/local/bin/../share/sdcc/non-free/lib/pic16" -I"/opt/local/share/sdcc/non-free/lib/pic16"
SDCC_INCLUDE_DIR = -I/opt/local/share/sdcc/non-free/include -I/opt/local/share/sdcc/non-free/include/pic16 -I/opt/local/share/sdcc/non-free/include -I/opt/local/share/sdcc/include/pic16
SDCC_LIB_DIR = "-L/opt/local/share/sdcc/lib/pic16 -L/opt/local/share/sdcc/lib/small-stack-auto"

all:	strtol protocol hd44780 ir_test

protocol: protocol.c
	sdcc \
	-g \
	--verbose \
	-V \
	--debug \
	-mpic16 \
	-p$(PROCESSOR) \
	-c $<

strtol:	strtol.c
	sdcc \
	-g \
	--verbose \
	-V \
	--debug \
	-mpic16 \
	-p$(PROCESSOR) \
	-c $<

hd44780: hd44780.c
	sdcc \
	--verbose \
	-V \
	--debug \
	-mpic16 \
	$(SDCC_INCLUDE_DIR) \
	-p$(PROCESSOR) \
	-c hd44780.c

ir_test: ir_test.c
	sdcc \
	--verbose \
	-V \
	--debug \
	-mpic16 \
	-I"./" strtol.o protocol.o hd44780.o \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

four_unsigned_char_to_unsigned_long: four_unsigned_char_to_unsigned_long.c
	sdcc \
	--verbose \
	-V \
	--debug \
	-mpic16 \
	-I"./" hd44780.o \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

four_unsigned_char_to_unsigned_long.hex: four_unsigned_char_to_unsigned_long.o
	gplink \
	-c \
	-o $@ \
	-m \
	-r \
	$(GPLINK_INCLUDE_DIR) \
	-I"./" strtol.o protocol.o hd44780.o \
	crt0.o libdev18f2455.lib libsdcc.lib libc18f.lib libio18f2455.lib \
	$^

four_unsigned_char_to_unsigned_long.o: four_unsigned_char_to_unsigned_long.asm
	gpasm \
	--extended \
	-pp$(PROCESSOR) \
	-c $<

four_unsigned_char_to_unsigned_long.asm: four_unsigned_char_to_unsigned_long.c
	sdcc \
	$(SDCC_INCLUDE_DIR) \
	$(SDCC_LIB_DIR) \
	-S \
	--debug \
	-mpic16 \
	--mplab-comp \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

ir_test.hex: ir_test.o
	gplink \
	-c \
	-o $@ \
	-m \
	-r \
	$(GPLINK_INCLUDE_DIR) \
	-I"./" strtol.o protocol.o hd44780.o \
	crt0.o libdev18f2455.lib libsdcc.lib libc18f.lib libio18f2455.lib \
	$^
#	-s 18f2550.lkr \


ir_test.o: ir_test.asm
	gpasm \
	--extended \
	-pp$(PROCESSOR) \
	-c $<

ir_test.asm: ir_test.c
	sdcc \
	$(SDCC_INCLUDE_DIR) \
	$(SDCC_LIB_DIR) \
	-S \
	--debug \
	-mpic16 \
	--mplab-comp \
	--use-crt=crt0.o \
	--use-non-free \
	-p$(PROCESSOR) $<

clean:
	rm -f *.adb *.asm *.cod *.cof *.hex *.lst *.map *.o *.sym *.lib

sim:
	/usr/local/bin/gpsim -pp$(PROCESSOR) -c ir_test.stc -s ir_test.cod ir_test.asm

sim_four:
	/usr/local/bin/gpsim -pp$(PROCESSOR) -s four_unsigned_char_to_unsigned_long.cod four_unsigned_char_to_unsigned_long.asm

flash:
	$(PK2CMD) -F ir_test.hex -M

#-Y

on:
	$(PK2CMD) -R -T

